define(function(require, exports, module) {
	
	require("form");
	var validator = require("validator");
	
	module.exports = function() {
		var params = {};
		var row = {};
		return {
			//国际化
			data: {
				title:$.i18n.prop("sys.account.manager.edit.title"),
				account:{
					label:$.i18n.prop("sys.account.manager.account"),
					placeholder:$.i18n.prop("sys.placeholder", [$.i18n.prop("sys.account.manager.account")]),
					valid:"required:true,max:50,ajax:{link:'/api/account/validateAccountEdit', name:'account'}",
					errors:"ajax:'"+$.i18n.prop("sys.unique", [$.i18n.prop("sys.account.manager.account")])+"'"
				},
				displayName:{
					label:$.i18n.prop("sys.account.manager.displayName"),
					placeholder:$.i18n.prop("sys.placeholder", [$.i18n.prop("sys.account.manager.displayName")])
				},
				password:{
					type: "password",
					label:$.i18n.prop("sys.account.manager.password"),
					placeholder:$.i18n.prop("sys.placeholder", [$.i18n.prop("sys.account.manager.password")])
				},
				status:{
					label:$.i18n.prop("sys.account.manager.status"),
					placeholder:$.i18n.prop("sys.placeholder", [$.i18n.prop("sys.account.manager.status")]),
					on:$.i18n.prop("sys.account.manager.status.active"),
					off:$.i18n.prop("sys.account.manager.status.locked"),
					value: "1"
				},
				memo:{
					label:$.i18n.prop("sys.memo"),
					placeholder:$.i18n.prop("sys.placeholder", [$.i18n.prop("sys.memo")])
				},
				button:{
					reset: $.i18n.prop("sys.reset"),
					submit: $.i18n.prop("sys.submit")
				}
			},
			methods: {
				init: function(data) {
					var me = this;
					params = data;
					row = params.row;
					validator.blur($(this.$el).find("form"));
					this.initForm();
					this.reset();
				},
				initForm:function() {
					this.account.valid = "required:true,max:50,ajax:{link:'/api/account/validateAccountEdit', name:'account', extraParams:{id:'" + row.id + "'}}";
				},
				reset: function() {
					var formValue = {};
					$.extend(formValue, row);
					formValue.password = "";
					$(this.$el).find("form").get(0).reset();
					$(this.$el).find("form").setFormValue(formValue);
					this.status.value = row.status + "";
				},
				submit : function() {
					var me = this;
					var form = $(this.$el).find("form");
					if(form.validate()) {
						this.loading();
						form.ajaxSubmit(function(data) {
							me.loading("close");
							if(data.success) {
								$.extend(row, data.message);
								params.update(row);
								me.closeWindow();
							} else if(data.message == 1) {
								$.alert($.i18n.prop("sys.unique", [$.i18n.prop("sys.account.manager.account")]));
							}
						});
					}
				},
				changePassworeType: function() {
					this.password.type = this.password.type == "text" ? "password" : "text"; 
				},
				destroy: function() {
					
				}
			}
		}
	}
});